from math import pi, atan, sqrt, ceil


def calculate_angle(point1, point2):
    '''
    根据两点坐标计算两点连线与横坐标的夹角弧度
    :param point1: 点一坐标
    :param point2:点二坐标
    :return:
    '''
    # 两个点的坐标
    x1, y1 = point1
    x2, y2 = point2

    # 计算斜率
    if x2 - x1 == 0:
        if y2 - y1 > 0:
            theta = pi / 2
        else:
            theta = 3 * pi / 2
    else:
        slope = (y2 - y1) / (x2 - x1)
        theta = atan(slope)

    return theta


def check(ball, left, right, up, bottom, all_balls):
    '''
    检查小球是否出现在不合理的位置，通常是由于计算机的离散计算导致的
    '''
    if ball.y - ball.radius < up - 5:
        print('up')
        ball.y = up + ball.radius
    if ball.y + ball.radius > bottom + 5:
        print('bottom')
        ball.y = bottom - ball.radius
    if ball.x - ball.radius < left - 5:
        print('left')
        ball.x = left + ball.radius
    if ball.x + ball.radius > right + 5:
        print('right')
        ball.x = right - ball.radius
    for i in all_balls:
        if i!=ball and sqrt((ball.x-i.x)**2+(ball.y-i.y)**2)<(ball.radius+i.radius)//2:
            print('allin')


def balls_map(radius, initx = 0, inity = 0):
    columns = [[0, 2, 4, 6, 8], [1, 3, 5, 7], [2, 4, 6], [3, 5], [4]]
    maps = dict()
    pre_x = 0
    for i, e in enumerate(columns):
        maps[pre_x + ceil(sqrt(3) * radius) + initx] = [j*(radius+1)+inity for j in e]
        pre_x = pre_x + ceil(sqrt(3) * radius) + 2
    print(maps)
    return maps


if __name__ == '__main__':
    balls_map(2)
